#region Usings

using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using xConnected.ActionFilter;
using xConnected.Core.Interfaces.Service;
using xConnected.Core.Model;

#endregion

namespace xConnected.Web.Controllers
{
    [SetCulture]
    public abstract class BaseController<T> : ApiController where T : PersistentEntity
    {
        protected IService<T> Service;

        public IEnumerable<T> GetAll()
        {
            var json = Service.GetAll();
            return json;
        }

        public T GetById(int id)
        {
            return Service.GetById(id);
        }

        //public virtual JsonResult SaveOrUpdate(T entity)
        //{
        //    var result = Service.SaveOrUpdate(entity);
        //    return result;
        //}

        //public virtual JsonResult Delete(int id)
        //{
        //    var entity = Service.GetById(id);
        //    Service.Delete(entity);
        //    return new JsonResult { Data = "", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        //}

        //#region JSON

        //public virtual JsonResult GetAll()
        //{
        //    var json = Service.GetAll().ToList().Select(o => o.Serialize()).ToList();
        //    return new JsonResult { Data = json, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        //}

        //public virtual JsonResult GetById(int id)
        //{
        //    return new JsonResult { Data = Service.GetById(id).Serialize(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        //}

        //public virtual JsonResult SaveOrUpdate(T entity)
        //{
        //    var result = Service.SaveOrUpdate(entity);
        //    return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        //}

        //public virtual JsonResult Delete(int id)
        //{
        //    var entity = Service.GetById(id);
        //    Service.Delete(entity);
        //    return new JsonResult { Data = "", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        //}

        //public virtual ViewResult SinglePage()
        //{
        //    return View();
        //}

        //#endregion
    }
}